<template>
    <div>
        
        <h1>会员新增</h1>
        <table class="table">
            <tr>
                <td>name</td>
                <td>
                    <input type="text" v-model="data.name">
                </td>
            </tr>
            <tr>
                <td>pwd</td>
                <td>
                    <input type="password" v-model="data.password">
                </td>
            </tr>
            <tr>
                <td>sex</td>
                <td>
                    <input type="radio" v-model="data.sex" value="男" name="1">男
                    <input type="radio" v-model="data.sex" value="女" name="1">女
                </td>
            </tr>
            <tr>
                <td>age</td>
                <td>
                    <input type="text" v-model="data.age">
                </td>
            </tr>
            <tr>
                <td>memberLevelId</td>
                <td>
                    <select v-model="data.memberLevelId">
                        <option value="0">请选择会员等级</option>
                        <option v-for="d in datas" :value="d.id">{{d.name}}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>houbbyString</td>
                <td>
                    <input type="checkbox" value="" name="" >游泳
                    <input type="checkbox" value="" name="" >唱歌
                    <input type="checkbox" value="" name="" >游戏
                    <input type="checkbox" value="" name="" >爬山
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="提交" class="btn btn-success" @click="add()">
                    <a href="/">会员列表</a>
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'; //从vue导入一个ref工具
import{useRouter}from 'vue-router';

const router=useRouter();//创建路由对象

const data=ref({
  "id": 0,
  "name": "",
  "password": "",
  "sex": "",
  "age": 0,
  "houbbyCount": 0,
  "houbbyString": "游泳",
  "isDelete": false,
  "img": "string",
  "memberLevelId": 0,
  "createData": "2025-04-21T11:24:12.687Z"
})
//保存功能
const add=()=>{
    axios.post("https://localhost:7043/api/MemBer/AddMemBer",data.value).then(res=>{
        if(res.data>0){
            alert('新增成功')
            router.push("/");
        }
        else{
            alert('新增失败')
        }
    })
}
//文档就绪函数
onMounted (()=>{
    getlist()
})
//会员等级使用的
const datas=ref([])//创建一个数组对象,实际用于保存所有的对象集合
//绑定下拉框
const getlist=()=>{
    axios.get("https://localhost:7043/api/MemberLevel/GetMemBerLevel").then(res=>{
        datas.value=res.data;
    })
}
</script>

<style scoped>

</style>